<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<head>
    <title>_登记退回单</title>
    <script type="text/javascript">
    
    var curOrderno='';
    var exceptionType='';
    
    $(function() {
	    exceptionType='${exceptionType}';
	    if(exceptionType=='refuse'){
	         $("#exceptiontype").html("拒收单");
	    }else if(exceptionType=='change'){
	    	$("#exceptiontype").html("换货单");
	    }else if(exceptionType=='lose'){
	        $("#exceptiontype").html("丢件单");
	    }else if(exceptionType=='outScope'){
	        $("#exceptiontype").html("超区单");
	    }
	    
	    
	    $("#orderno").focus(); 
	    $("#orderno").val(''); 
        $("#btn_regist").hide();
        $("[name='exist']").hide();
        $("[name='noexist']").show();
        $("#msg").html("");
        $("#mark").val('')
        curOrderno='';
        
	    
    });
	
	function query(){
        
        var orderno=$("#orderno").val().trim();
        $("#btn_regist").hide();
        $("[name='exist']").hide();
        $("[name='noexist']").show();
        $("#msg").html("");
        curOrderno='';
        
        if(orderno==''){
           $("#msg").css("color","red");
		   $("#msg").html("请输入订单编号！");
		   $("#_orderno").focus(); 
		   $("#_orderno").val(''); 
		   curOrderno='';
		   return false;
        }
        
        $.ajax({
 			type:'post',
 			url:'${ctx}/v2/backOrder/ajaxQueryBackOrder',
 			data:{
 				orderno:orderno
 			},
 			dataType:'json',
 			success:function(data) {
 				
 				var msg=data.msg;
 				var ediOrder=data.ediOrder;
				var workOrder=data.workOrder;
				
 				if(msg=='noExist'){
 				   $("#msg").css("color","red");
				   $("#msg").html("不存在此运单号！");
 				   $("#orderno").val('');
				   $("#orderno").focus();
				   $("[name='exist']").hide();
				   $("[name='noexist']").show();
 				}
 				else if(msg=='registed'){
 				   $("#msg").css("color","red");
				   $("#msg").html("此单已经登记，不能重复登记！");
 				   showOrderInfo(ediOrder,workOrder);
 				   $("#orderno").val('');
				   $("#orderno").focus();
 				}
 				else if(msg=='unSended'){
 				   $("#msg").css("color","red");
				   $("#msg").html("此单未发货，不能登记！");
 				   showOrderInfo(ediOrder,workOrder);
 				   $("#orderno").val('');
				   $("#orderno").focus();
 				}
 				else if(ediOrder.customerCode=='MID'){
 				   $("#msg").css("color","red");
				   $("#msg").html("美的的订单不允许登记异常单，请联系美的驻仓人员");
 				   showOrderInfo(ediOrder,workOrder);
 				   $("#orderno").val('');
				   $("#orderno").focus();
 				}
 				else{
 				   curOrderno=ediOrder.ordeno;
 				   showOrderInfo(ediOrder,workOrder);
 				   $("#btn_regist").show();
 				}
 				
 			},
 			error:function() {
 				alert("网络繁忙，请稍后重试...");
 			}
 	   });
     }
     
      function showOrderInfo(ediOrder,workOrder){
	       $("[name='exist']").show();
	       $("[name='noexist']").hide();
	       $("#ordeno").html("<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+ediOrder.ordeno+"' target='_blank' >"+ediOrder.ordeno+"</a>");
	       $("#customerOrderno").html(ediOrder.customerOrdeno);
	       $("#fromno").html(ediOrder.fromno);
	       $("#express").html(workOrder.expressNo+" "+workOrder.ebillNo);
	       $("#expressName").html(ediOrder.cacode);
	       $("#address").html(ediOrder.addres);
	       $("#postco").html(ediOrder.postco);
	       $("#custna").html(ediOrder.custna);
	       $("#mobile").html(ediOrder.mobile);
	       $("#teleph").html(ediOrder.teleph);
	       
	       var status=workOrder.status;
	       if(status=='1'){ 
	    	   $("#status").html("创建批次");
	       }else if(status=='2'){
	    	   $("#status").html("创建任务");
	       }else if(status=='3'){
	    	   $("#status").html("已拣货");
	       }else if(status=='4'){
	    	   $("#status").html("已灯光拣选");
	       }else if(status=='5'){
	    	   $("#status").html("已包装");
	       }else if(status=='6'){
	    	   $("#status").html("已发货");
	       }
     }
     
     //登记
     function regist(){
        var btn=$("#btn_regist");
        btn.attr("disabled",true);
        
        var mark=$("#mark").val().trim();
        if(mark==''){
           alert("请填写备注信息..");
           $("#mark").focus();
	       btn.attr("disabled",false);
	       return;
        }
        
        $.ajax({
 			type:'post',
 			url:'${ctx}/v2/backOrder/ajaxBackOrderRegist',
 			data:{
 				orderno:curOrderno,
 				exceptionType:exceptionType,
 				mark:mark
 			},
 			dataType:'json',
 			success:function(data) {
 			
 				var msg=data.msg;
 				
 			    if(msg=='success'){ //取消成功
 				     $("#msg").css("color","green");
				     $("#msg").html("登记成功。");
				     btn.hide();
				     curOrderno='';
 				}else if(msg=='registed'){
 				     $("#msg").css("color","red");
				     $("#msg").html("此单已经登记，不能重复登记。");
 				
 				}else if(msg=='unSended'){
 				     $("#msg").css("color","red");
				     $("#msg").html("此单未发货，不能登记！");
				     
 				}else{
 				     alert("网络繁忙，请稍后重试...");
 				}
 				
 				btn.attr("disabled",false);
 				$("#orderno").val('');
 				$("#mark").val('');
			    $("#orderno").focus();
			    $("[name='exist']").hide();
			    $("[name='noexist']").show();
 				
 			},
 			error:function() {
 				alert("网络繁忙，请稍后重试...");
 				btn.attr("disabled",false);
 			}
 	   });
        
     }
    
    </script>
</head>
<body>
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">登记<span id="exceptiontype"></span></h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">	
<table class="table table-bordered table-condensed" style="margin-top: 0px;">
		<tr>  
		   <td style="width: 150px; text-align: right; vertical-align: middle;">订单号：</td>
		   <td style="vertical-align: middle;">
		     <input type="text" id="orderno" style="height: 30px; margin-top: 7px;" onchange="query();" />
		     <span style="margin-left:12px; margin-top: 10px; color: red;font-weight: bold;" id="msg"></span>
		   </td>
		</tr>
		
		<tr> 
		   <td style="width: 150px;text-align: right; vertical-align: middle;">备注原因：</td>
		   <td style="vertical-align: middle;">
		      <textarea id="mark" style="margin-top: 7px; width: 300px;" ></textarea>
		   </td>
		</tr>
		
       </table>    
    </div>
	</div>
	</div>
	</div>
    
    <div class="row">
		<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">订单信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">	
    <!-- 订单信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		<thead name="exist" style="display: none;">
		    <th>能容订单号</th>
		    <th>商家订单号</th>
		    <th>来源订单号</th>
			<th>快递单号</th>
			<th>快递公司</th>
			<th>收货人</th>
			<th>联系手机</th>
			<th>联系座机</th>
			<th>收货人地址</th>
			<th>订单状态</th>
		</thead>
		
		<tr name="exist" style="display: none;">
		    <td id="ordeno"></td>
		    <td id="customerOrderno"></td>
		    <td id="fromno"></td>
		    <td id="express"></td>
		    <td id="expressName"></td>
		    <td id="custna"></td>
		    <td id="mobile"></td>
		    <td id="teleph"></td>
		    <td id="address"></td>
		    <td id="status"></td>
		  </tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	<div class="modal-footer bg-gray">
			<a href="${ctx}/v2/backOrder/show" role="button"  class="btn btn-info" >返回</a>
			<button class="btn btn-primary" id="btn_regist" style="display: none;"  onclick="regist();">登记</button>
	</div>
	</section>
</body>
</html>